﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using AnguaRPGEngine.Library.Systems;
using System.Drawing.Drawing2D;

namespace AnguaRPGEngine.Library.Dice
{
     public class D4:IDie
    {
        #region ctor
        public D4()
        {
        }
        
        #endregion
        #region IDie Members
        #region Image
        public System.Drawing.Bitmap Image
        {
            get
            {
                Font dieFont = new Font(FontFamily.GenericSansSerif, 12f);
                Bitmap i = ImageLibrary.Instance.GetImageFromLibrary(string.Format("Dice.{0}.D{1}", DieRoller.Instance.DiceCollection.CurrentSet.PathName, Sides, _Value));
                using (Graphics g = Graphics.FromImage(i))
                {

                    g.DrawString(Value.ToString(), dieFont, new SolidBrush(DieRoller.Instance.DiceCollection.CurrentSet.PipColorAsColor()), new PointF(26, 5));

                    Matrix matrix = new Matrix();
                    matrix.Rotate(-121);
                    g.Transform = matrix;
                    g.DrawString(SelectBottomLeft(Value.ToString()), dieFont, new SolidBrush(DieRoller.Instance.DiceCollection.CurrentSet.PipColorAsColor()), new PointF(-57, -20));
                    
                    g.ResetTransform();

                    matrix.Reset();
                    matrix.Rotate(119);
                    g.Transform = matrix;
                    g.DrawString(SelectBottomRight(Value.ToString()), dieFont, new SolidBrush(DieRoller.Instance.DiceCollection.CurrentSet.PipColorAsColor()), new PointF(10, -79));
                }
                return i;
            }
        }
        #endregion
        #region Sides
        public int Sides
        {
            get
            {
                return 4;
            }
        }
        #endregion
        #region Value
        private int _Value = 1;
        public int Value
        {
            get
            {
                return _Value;
            }
        }
        #endregion
        #region Roll
        public void Roll()
        {
            _Value = Randomizer.Instance.NextInt(1, Sides);
        }
        #endregion
        #endregion
        private string SelectBottomRight(string Die)
        {
            switch (Die)
            {
                case "1":
                    return "2";
                case "2":
                    return "3";
                case "3":
                    return "1";
            }
            return "2";
        }
        private string SelectBottomLeft(string Die)
        {
            switch (Die)
            {
                case "1":
                    return "3";
                case "2":
                    return "1";
                case "3":
                    return "2";
            }
            return "1";
        }     
    }
}
